import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/viewmodel/food/regular_week_menu_view_model.dart';

import '../../net/response/food/scan_old_data.dart';

class RegularWeekMenuPage extends BaseStatefulMvvmWidget {
  final String time;
  final String siteId;
  final String orderModelType;
  final ScanOldData? oldData;
  final PickerDataWithIdModel? useType;

  RegularWeekMenuPage(
      {required this.time,
      required this.siteId,
      required this.orderModelType,
      this.oldData,this.useType});

  @override
  State<StatefulWidget> createState() => _RegularWeekMenuState();
}

class _RegularWeekMenuState
    extends BaseMvvmState<RegularWeekMenuViewModel, RegularWeekMenuPage> {
  @override
  Widget buildLoadingContentView() {
    return viewModel.menuContent();
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text('周菜单'),
        actions: [
          CommonText('下单').onTap(() {
            viewModel.submitWeek();
          }).addToContainer(
              alignment: Alignment.center, margin: EdgeInsets.only(right: 16))
        ],
      ),
      body: loadingContentWidget,
    );
  }

  @override
  RegularWeekMenuViewModel createViewModel() {
    return RegularWeekMenuViewModel(context,
        siteId: widget.siteId,
        time: widget.time,
        orderModelType: widget.orderModelType,
    oldData:widget.oldData,useType: widget.useType?.pickId);
  }

  @override
  void onRetryClick() {
    viewModel.requestRefresh();
  }
}
